package com.smart.community.property.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import com.smart.community.commons.dto.FileInfoDTO;

/**
 * 物业公司视图对象
 * @author Wu.Liang
 * @since 2025-06-29
 */
@Data
@Schema(description = "物业公司视图对象")
public class PropertyCompanyVO {

    @Schema(description = "物业公司ID")
    private Long id;

    @Schema(description = "公司编码")
    private String companyCode;

    @Schema(description = "公司名称")
    private String companyName;

    @Schema(description = "统一社会信用代码")
    private String creditCode;

    @Schema(description = "营业执照号")
    private String businessLicense;

    @Schema(description = "法定代表人")
    private String legalRepresentative;

    @Schema(description = "联系人")
    private String contactPerson;

    @Schema(description = "联系电话")
    private String contactPhone;

    @Schema(description = "联系邮箱")
    private String contactEmail;

    @Schema(description = "邮箱地址")
    private String email;

    @Schema(description = "公司地址")
    private String address;

    @Schema(description = "公司简介")
    private String introduction;

    @Schema(description = "公司描述")
    private String description;

    @Schema(description = "备注")
    private String remark;

    @Schema(description = "注册资本(万元)")
    private BigDecimal registeredCapital;

    @Schema(description = "成立日期")
    @JsonFormat(pattern = "yyyy-MM-dd")
    private LocalDate establishedDate;

    @Schema(description = "资质等级")
    private String qualificationLevel;

    @Schema(description = "服务范围")
    private String serviceScope;

    @Schema(description = "营业时间")
    private String businessHours;

    @Schema(description = "服务热线")
    private String serviceHotline;

    @Schema(description = "支付宝商户号")
    private String alipayMerchantId;

    @Schema(description = "微信支付商户号")
    private String wechatPayMerchantId;

    @Schema(description = "收款账户")
    private String paymentAccount;

    @Schema(description = "开户银行")
    private String paymentBank;

    @Schema(description = "在线支付链接")
    private String paymentLink;

    @Schema(description = "收款二维码图片信息，JSON格式存储多个文件信息")
    private String paymentQrCode;

    @Schema(description = "公司Logo图片信息，JSON格式存储多个文件信息")
    private String companyLogo;

    @Schema(description = "状态：0-禁用，1-启用，2-待审核，3-审核拒绝")
    private Integer status;

    @Schema(description = "状态名称")
    private String statusName;

    @Schema(description = "审核状态：0-待审核，1-审核通过，2-审核拒绝")
    private Integer auditStatus;

    @Schema(description = "审核状态名称")
    private String auditStatusName;

    @Schema(description = "审核人ID")
    private Long auditBy;

    @Schema(description = "审核人姓名")
    private String auditByName;

    @Schema(description = "审核时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime auditTime;

    @Schema(description = "审核备注")
    private String auditRemark;

    @Schema(description = "排序")
    private Integer sortOrder;

    @Schema(description = "是否删除：0-否，1-是")
    private Integer deleted;

    @Schema(description = "版本号")
    private Integer version;

    @Schema(description = "创建人ID")
    private Long createBy;

    @Schema(description = "创建人姓名")
    private String createByName;

    @Schema(description = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @Schema(description = "更新人ID")
    private Long updateBy;

    @Schema(description = "更新人姓名")
    private String updateByName;

    @Schema(description = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    // ==================== 文件信息相关方法 ====================

    /**
     * 获取收款二维码文件信息列表
     * 
     * @return 文件信息列表
     */
    public List<FileInfoDTO> getPaymentQrCodeFiles() {
        return com.smart.community.commons.utils.FileInfoUtils.fromJsonString(paymentQrCode);
    }

    /**
     * 设置收款二维码文件信息列表
     * 
     * @param fileInfoList 文件信息列表
     */
    public void setPaymentQrCodeFiles(List<FileInfoDTO> fileInfoList) {
        this.paymentQrCode = com.smart.community.commons.utils.FileInfoUtils.toJsonString(fileInfoList);
    }

    /**
     * 获取公司Logo文件信息列表
     * 
     * @return 文件信息列表
     */
    public List<FileInfoDTO> getCompanyLogoFiles() {
        return com.smart.community.commons.utils.FileInfoUtils.fromJsonString(companyLogo);
    }

    /**
     * 设置公司Logo文件信息列表
     * 
     * @param fileInfoList 文件信息列表
     */
    public void setCompanyLogoFiles(List<FileInfoDTO> fileInfoList) {
        this.companyLogo = com.smart.community.commons.utils.FileInfoUtils.toJsonString(fileInfoList);
    }

    /**
     * 获取第一个收款二维码文件URL（兼容旧数据）
     * 
     * @return 第一个文件URL
     */
    public String getFirstPaymentQrCodeUrl() {
        return com.smart.community.commons.utils.FileInfoUtils.getFirstFileUrlFromJson(paymentQrCode);
    }

    /**
     * 获取第一个公司Logo文件URL（兼容旧数据）
     * 
     * @return 第一个文件URL
     */
    public String getFirstCompanyLogoUrl() {
        return com.smart.community.commons.utils.FileInfoUtils.getFirstFileUrlFromJson(companyLogo);
    }

    /**
     * 获取收款二维码文件数量
     * 
     * @return 文件数量
     */
    public int getPaymentQrCodeFileCount() {
        return com.smart.community.commons.utils.FileInfoUtils.getFileCount(paymentQrCode);
    }

    /**
     * 获取公司Logo文件数量
     * 
     * @return 文件数量
     */
    public int getCompanyLogoFileCount() {
        return com.smart.community.commons.utils.FileInfoUtils.getFileCount(companyLogo);
    }

    /**
     * 检查是否有收款二维码文件
     * 
     * @return 是否有文件
     */
    public boolean hasPaymentQrCodeFiles() {
        return getPaymentQrCodeFileCount() > 0;
    }

    /**
     * 检查是否有公司Logo文件
     * 
     * @return 是否有文件
     */
    public boolean hasCompanyLogoFiles() {
        return getCompanyLogoFileCount() > 0;
    }

    // ==================== 兼容旧数据的方法 ====================

    /**
     * 设置收款二维码URL（兼容旧数据）
     * 
     * @param paymentQrCodeUrl 收款二维码URL
     */
    public void setPaymentQrCodeUrl(String paymentQrCodeUrl) {
        if (paymentQrCodeUrl != null) {
            List<FileInfoDTO> fileInfoList = com.smart.community.commons.utils.FileInfoUtils
                .fromSingleFileUrl(paymentQrCodeUrl, "PAYMENT_QR", "WEB");
            this.paymentQrCode = com.smart.community.commons.utils.FileInfoUtils.toJsonString(fileInfoList);
        }
    }

    /**
     * 设置公司Logo URL（兼容旧数据）
     * 
     * @param companyLogoUrl 公司Logo URL
     */
    public void setCompanyLogoUrl(String companyLogoUrl) {
        if (companyLogoUrl != null) {
            List<FileInfoDTO> fileInfoList = com.smart.community.commons.utils.FileInfoUtils
                .fromSingleFileUrl(companyLogoUrl, "COMPANY_LOGO", "WEB");
            this.companyLogo = com.smart.community.commons.utils.FileInfoUtils.toJsonString(fileInfoList);
        }
    }
} 